import jsp_instance
import numpy as np

jsp_instance_data = jsp_instance.get("k1")
num_machines = jsp_instance_data["machines"]

num_workers = np.random.randint(1, num_machines + 1)

data = jsp_instance_data["data"]
data += f"{num_workers}\n"
for worker_idx in range(num_workers):
    worker_machine_count = np.random.randint(1, num_machines + 1)
    machines = np.random.choice(num_machines, worker_machine_count, replace=False)
    data += f"{worker_machine_count} {" ".join(str(machine_idx) for machine_idx in sorted(machines))}\n"

# idle energy consumption
data += (
    " ".join(str(round(np.random.uniform(1, 2), 2)) for _ in range(num_machines)) + "\n"
)
# workload energy consumption
data += " ".join(str(np.random.randint(10, 12)) for _ in range(num_machines)) + "\n"

jsp_instance_data["worker"] = num_workers
jsp_instance_data["data"] = data

with open("./drcfjsp_data.txt", "w", encoding="utf-8") as file:
    file.write(jsp_instance_data["data"])

# <Number of Jobs> <Number of Machines>
# For each job:
#   <Number of Operations>
#   For each operation:
#     <Number of Machines for this operation>
#       For each machine:
#         <Machine ID> <Processing Time>
# <Number of Workers>
# For each worker:
#   <Worker Machine Count>
#   For each machine:
#       <Machine ID>
# For each machine:
#   <Idle Energy Consumption>
# For each machine:
#   <Workload Energy Consumption>
